﻿using System.Diagnostics;

using Outcoder;
using Outcoder.ApplicationModel;
using Outcoder.ComponentModel.StatePreservation;
using Outcoder.Concurrency;
using Outcoder.InversionOfControl;
using Outcoder.InversionOfControl.Containers.SimpleContainer;
using Outcoder.LauncherModel.Launchers;
using Outcoder.Logging;
using Outcoder.Logging.Loggers;
using Outcoder.Messaging;
using Outcoder.NavigationModel;
using Outcoder.Services;
using Outcoder.Services.Implementation;
using Outcoder.UserOptionsModel;

namespace CalciumTemplateApp
{
	/// <summary>
	/// This class initializes various key services. 
	/// Type registrations occur based on the build configuration.
	/// </summary>
	class Bootstrapper
	{
		internal bool RestoreTransientState { get; set; }

		public void Run()
		{
			var calciumSystem = new CalciumSystem();
			calciumSystem.Initialize();

			var marketPlaceServiceMock = new MockMarketplaceService { Trial = true };
			Dependency.Register<IMarketplaceService>(marketPlaceServiceMock);

			AppSettings.InitializeUserOptions();

			InitializeContainer();
		}

		/// <summary>
		/// Initializes the IoC container by registering type associations 
		/// and singleton instances.
		/// </summary>
		void InitializeContainer()
		{
			/* Add type registrations here. */

			/* Build configuration specific registerations. */
			if (DeploymentConfiguration.DebugBuild)
			{
				RegisterDebugTypes();
			}
			else
			{
				RegisterReleaseTypes();
			}
		}

		/// <summary>
		/// Registers the debug types. 
		/// Mock types are used for types that cause the app to be deactivated.
		/// </summary>
		void RegisterDebugTypes()
		{
			/* This registration overrides the CalciumSystem registration. */
			Dependency.Register<IMarketplaceService>(new MockMarketplaceService { Trial = true });
		}

		/// <summary>
		/// Registers the release types. 
		/// Since the app will fail marketplace certification if the assembly 
		/// is built using a debug configuration, the release configuration 
		/// guarantees that no mock type registrations will make it into a published app.
		/// </summary>
		void RegisterReleaseTypes()
		{
			//Dependency.Register<ISomeType, SomeType>();
		}
	}
}
